import { ObservedMap } from "../libs/ObservedMap";
import { debug } from "@tauri-apps/plugin-log";

export const Stateful = (target: any, prop: string | symbol, descriptor: PropertyDescriptor) => {
    Reflect.defineMetadata('__ob', true, target, prop);
    const method = descriptor.value;
    descriptor.value = function (...args: any[]) {
        debug(`${target.constructor.name}::${prop.toString()} called.`);
        ObservedMap.componentTree.stack.forEach(e => e.remove());
        method.apply(this, args);
    };
}